import QtQuick

/*
  自定义组件：菜单
  依赖的自定义组件：TextBtn.qml
*/
Rectangle {
    id: customMenu
    width: 120
    height: 80
    visible: false
    radius: 8

    signal customMenuClicked(var index)

    property color cmTextColor: "#000000" // 文本颜色
    property int cmFontSize: 14 // 字体大小
    property alias cmListModel: customMenuListModel // 下拉菜单按键model
    property color cmHoverColor: "#4F4F4F" // 悬停过渡颜色
    property double cmItemHeight: 30 // 列表按键各自的高度

    function open(x, y) {
        customMenu.x = x
        customMenu.y = y
        customMenu.focus = true
        customMenu.visible = true
    }

    onFocusChanged: {
        visible = false
    }

    ListModel {
        id: customMenuListModel
        ListElement { mText: "text1"}
    }

    ListView {
        id: customMenuListView
        anchors.fill: parent
        clip: true
        interactive: false

        model: customMenuListModel
        delegate: TextBtn {
            width: parent.width
            height: cmItemHeight
            tbText: mText
            tbBackColor: "transparent"
            tbColor: cmTextColor
            tbHoverColor: cmHoverColor
            tbFontSize: cmFontSize
            tbTextHAlign: Text.AlignLeft
            tbTextX: 14
            tbRadius: customMenu.radius

            onClicked: {
                customMenu.focus = !customMenu.focus
                customMenuClicked(index)
            }
        }
    }
}
